package cn.rongdao.jrkabao.widget;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.mifengkong.frtools.util.FRString;

import cn.rongdao.jrkabao.R;
import cn.rongdao.jrkabao.util.CommonUtil;


/**
 *
 */

public class DialogCashQuotaFull extends Dialog {
    public DialogCashQuotaFull(Context context) {
        super(context);
    }

    public DialogCashQuotaFull(Context context, int themeResId) {
        super(context);
    }

    protected DialogCashQuotaFull(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    public static class Builder {

        /**
         * Helper class for creating a custom dialog
         */

        private Activity activity;
        private String title;
        private String content;
        private String buttonText;
        private String buttonType;
        private View.OnClickListener onClickListener;

        public Builder(Activity activity) {
            this.activity = activity;
        }

        /**
         * Set the Dialog title from resource
         *
         * @param title
         * @return
         */
        public DialogCashQuotaFull.Builder setTitle(int title) {
            this.title = (String) activity.getText(title);
            return this;
        }

        /**
         * Set the Dialog content from String
         *
         * @param content
         * @return
         */
        public DialogCashQuotaFull.Builder setContent(String content) {
            this.content = content;
            return this;
        }

        /**
         * Set the Dialog buttonText from String
         *
         * @param buttonText
         * @return
         */
        public DialogCashQuotaFull.Builder setButtonText(String buttonText) {
            this.buttonText = buttonText;
            return this;
        }

        /**
         * Set the Dialog buttonType from String
         *
         * @param buttonType
         * @return
         */
        public DialogCashQuotaFull.Builder setButtonType(String buttonType) {
            this.buttonType = buttonType;
            return this;
        }

        /**
         * Set the Dialog ButtonOnClickListener
         *
         * @param onClickListener
         * @return
         */
        public DialogCashQuotaFull.Builder setButtonConfirmOnClickListener(View.OnClickListener onClickListener) {
            this.onClickListener = onClickListener;
            return this;
        }

        /**
         * Set the Dialog title from String
         *
         * @param title
         * @return
         */
        public DialogCashQuotaFull.Builder setTitle(String title) {
            this.title = title;
            return this;
        }

        /**
         * Create the custom dialog
         */
        public DialogCashQuotaFull create() {
            final DialogCashQuotaFull dialog = new DialogCashQuotaFull(activity, R.style.Dialog);
            dialog.setCanceledOnTouchOutside(false);
            Window window = dialog.getWindow();
            //取消标题
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            //取消状态栏
            window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
            window.setBackgroundDrawable(new ColorDrawable());
            window.setContentView(R.layout.dialog_cash_quota_full);
            TextView tvContent = window.findViewById(R.id.dcqf_tv_content);
            TextView tvCancelButton = window.findViewById(R.id.dcqf_tv_cancel_button);
            TextView tvConfirmButton = window.findViewById(R.id.dcqf_tv_confirm_button);
            View viewLine = window.findViewById(R.id.dcqf_view_line);

            tvContent.setText(FRString.isEmpty(content) ? "" : content);
            tvCancelButton.setText(!FRString.isEmpty(buttonText) ? buttonText : "取消");
            if (FRString.isEmpty(buttonText)) {
                viewLine.setVisibility(View.VISIBLE);
                tvConfirmButton.setVisibility(View.VISIBLE);
                tvConfirmButton.setText((CommonUtil.isStatusSuccess(buttonType) ? "确定交易" : "更换卡"));
            }

            tvCancelButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                }
            });

            tvConfirmButton.setOnClickListener(onClickListener);

            return dialog;
        }
    }
}
